import redis

#定义地址和端口
host = '127.0.0.1'
port = 6379

#建立redis连接
r = redis.Redis(host=host,port=port)

# 有序集合
r.zadd('myrank', {'car': 100})
r.zadd('myrank', {'phone': 30})
# 清空删除
# r.delete("myrank")
# 修改操作
newcore = r.zincrby('myrank',-300,'phone')
print(newcore)
# 遍历有序集合
print(r.zrange('myrank', 0, 10, desc=True, withscores=True))
# 赋值
myrank = r.zrange('myrank', 0, 10, desc=True, withscores=True)

# r.expire("myrank",60)
# 显示到期时间
print(r.ttl("myrank"))
# 取值
print(myrank[0][1])



# 生命周期的使用
# r.set("123","123")
# r.expire("123",10)
# print(r.get("123"))




# # list的使用
# r.lpush("testlist",1)
# print(r.llen("testlist"))

# mylist = r.lrange('testlist',0,r.llen("testlist"))
# # r.delete("testlist")
# print(mylist)




# #声明一个值
# r.set('test','123')

# #取值
# code = r.get('test')

# #转码
# code = code.decode('utf-8')

# print(code)


